package cn.xtxfan.infrastructure.persistent.repository;

import cn.xtxfan.domain.user.model.dto.CheckUserDTO;
import cn.xtxfan.domain.user.model.entity.CheckUserEntity;
import cn.xtxfan.domain.user.repository.IUserRepository;
import cn.xtxfan.infrastructure.persistent.dao.ICheckUserDao;
import cn.xtxfan.infrastructure.persistent.po.CheckUser;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @className: UserRepository
 * @author: XTX
 * @date: 2025/7/19 16:18
 * @Version: 1.0
 * @description:
 */
@Repository
public class UserRepository implements IUserRepository {

    @Resource
    private ICheckUserDao checkUserDao;

    @Override
    public CheckUserDTO queryCheckUser(CheckUserEntity checkUserEntity) {
        CheckUser checkUser = CheckUser.builder()
                .username(checkUserEntity.getUsername())
                .password(checkUserEntity.getPassword())
                .userId(checkUserEntity.getUserId())
                .build();

        CheckUser checkUserRes = checkUserDao.queryCheckUser(checkUser);
        if (checkUserRes == null) return null;

        return CheckUserDTO.builder()
                .nickname(checkUserRes.getNickname())
                .userId(checkUserRes.getUserId())
                .sex(checkUserRes.getSex())
                .build();
    }
}

